import { U, S, mapField } from '../../lib/backend'
import axios from 'axios'
import env from '../../config/common'

export default {
  getLessonList ({ dispatch, commit, state, rootState }, info) {
    const URL =
      env.CRM_API_HOST +
      '/admin/xcx/' +
      rootState.auth.user.token +
      '/sites/' +
      rootState.auth.site_id +
      '/courses'
    // const URL =
    //   'http://rap2api.taobao.org/app/mock/2717/admin/xcx//%7Btoken%7D/sites/%7Bsite_id%7D/courses'
    return axios.get(URL + '?' + U(info))
  },
  deleteLesson ({ dispatch, commit, state, rootState }, info) {
    const URL =
      env.CRM_API_HOST +
      '/admin/xcx/' +
      rootState.auth.user.token +
      '/sites/' +
      rootState.auth.site_id +
      '/del/course'
    // const URL =
    //   'http://rap2api.taobao.org/app/mock/2717/admin/xcx//%7Btoken%7D/sites/%7Bsite_id%7D/del/course'
    return axios.post(URL, mapField(info, {
      id: 'id'
    }))
  },
  saveLesson ({ dispatch, commit, state, rootState }, info) {
    const URL =
      env.CRM_API_HOST +
      '/admin/xcx/' +
      rootState.auth.user.token +
      '/sites/' +
      rootState.auth.site_id +
      '/edit/course'
    // const URL =
    //   'http://rap2api.taobao.org/app/mock/2717/admin/xcx//%7Btoken%7D/sites/%7Bsite_id%7D/del/course'
    return axios.post(URL, info)
  },
  addLesson ({ dispatch, commit, state, rootState }, info) {
    const URL =
      env.CRM_API_HOST +
      '/admin/xcx/' +
      rootState.auth.user.token +
      '/sites/' +
      rootState.auth.site_id +
      '/course'
    // const URL =
    //   'http://rap2api.taobao.org/app/mock/2717/admin/xcx//%7Btoken%7D/sites/%7Bsite_id%7D/del/course'
    return axios.post(URL, info)
  },
  getLesson ({ dispatch, commit, state, rootState }, info) {
    const URL =
      env.CRM_API_HOST +
      '/admin/xcx/' +
      rootState.auth.user.token +
      '/sites/' +
      rootState.auth.site_id +
      '/detail/course'
    // const URL =
    //   'http://rap2api.taobao.org/app/mock/2717/admin/xcx//%7Btoken%7D/sites/%7Bsite_id%7D/detail/course'
    return axios.get(URL + '?' + U(info))
  }
}
